#!/bin/bash
#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#
#   @filename: webhook_notice
#   @author: 沈风
#   @date: 2024-06-25 10:07
#   @description: 飞书webhook通知
#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#
function FeishuWebhookUserID() {
  case ${1} in
  "赵正文")
    user_id=ou_7f911edc7dda5a32702115a2ca6eeb19
  ;;
  "许伟")
    user_id=ou_1d2d398f6398c767d0a17a803c5f7790
  ;;
  *)
    user_id=ou_7f911edc7dda5a32702115a2ca6eeb19
  ;;
  esac
}

function FeishuWebhookInform() {
    curl -X POST \
      $api \
      -H 'Content-Type: application/json' \
      -d '{
      "msg_type": "post",
      "content": {
          "post": {
              "zh_cn": {
                  "title": "jenkins构建通知",
                  "content": [
                      [{
                          "tag": "text",
                          "text": "构建项目: self-low-code-template\n"
                      },
                      {
                          "tag": "text",
                          "text": "构建状态: < '${1}' >\n"
                      },
                      {
                          "tag": "text",
                          "text": "构建时间: '${submit_time}'\n"
                      },
                      {
                          "tag": "text",
                          "text": "构建分支: '${branch_name}'"
                      }

                     ]
                  ]
              }
          }
      }
  }'
}

# 获取分支名
branch_name="${1}"
# 获取提交者
submitter="${2}"
# 获取构建状态
submit_status="${3}"
# 获取构建时间
submit_time="${4}"

FeishuWebhookUserID $submitter

#飞书机器人webhook 地址
api=https://open.feishu.cn/open-apis/bot/v2/hook/435ed460-d588-4b1d-9ead-844caf0e3338

if [ "${submit_status}" == "0" ]; then
  FeishuWebhookInform "成功"
else
  FeishuWebhookInform "失败"
fi



